package com.wiloon.androidx;

import com.wiloon.androidx.R;
import com.wiloon.androidx.R.layout;
import com.wiloon.androidx.R.menu;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.Menu;
import android.widget.Toast;

public class ContentProviderActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_content_provider);
		displayRecords();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.content, menu);
		return true;
	}

	private void displayRecords() {

		String columns[] = new String[] { People.NAME, People.NUMBER };
		Uri mContacts = People.CONTENT_URI;
		Cursor cur = managedQuery(mContacts, columns, null, null, null);
		if (cur.moveToFirst()) {
			String name = null;
			String phoneNo = null;
			do {
				name = cur.getString(cur.getColumnIndex(People.NAME));
				phoneNo = cur.getString(cur.getColumnIndex(People.NUMBER));
				Toast.makeText(this, name + " " + phoneNo, Toast.LENGTH_LONG)
						.show();
			} while (cur.moveToNext());
		}
	}
}
